//
//  LGSmokeProgressView.m
//  XieHeHeartDisease
//
//  Created by 1234 on 2024/1/31.
//  戒烟进度

#import "LGDrinkProgressView.h"

@interface LGDrinkProgressView()
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIImageView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UIView *bottomView;
/**   */
@property (nonatomic , strong)UILabel *currentLabel;
/**   */
@property (nonatomic , strong)UILabel *totalLabel;
/**   */
@property (nonatomic , strong)UILabel *tipLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , strong)UIView *progressView;
/**   */
@property (nonatomic , strong)UILabel *percentLabel;

@end

@implementation LGDrinkProgressView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    if([dataDic isKindOfClass:[NSDictionary class]] && dataDic.allKeys.count>0){
        self.contentLabel.text = LGNSString(dataDic[@"title"]);
        self.currentLabel.text = [NSString stringWithFormat:@"记录 %@ 天",dataDic[@"record_days"]];
        self.totalLabel.text = [NSString stringWithFormat:@"/进行 %@ 天",dataDic[@"progress_days"]];
        self.percentLabel.text = LGNSString(dataDic[@"success_perecent"]);
        CGFloat percent = [dataDic[@"success_days"] floatValue] / [dataDic[@"record_days"] floatValue];
        percent = (percent>0)?percent:0.0;
        CGFloat width = self.lineView.bounds.size.width * percent;
        self.progressView.frame = CGRectMake(0, 0, width, viewPix(8));
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self addSubview:self.titleLabel];
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.contentLabel];
    [self.baseView addSubview:self.bottomView];
    [self.baseView addSubview:self.currentLabel];
    [self.baseView addSubview:self.totalLabel];
    [self.baseView addSubview:self.tipLabel];
    [self.baseView addSubview:self.lineView];
    [self.lineView addSubview:self.progressView];
    [self.baseView addSubview:self.percentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.baseView).offset(viewPix(24));
        make.right.equalTo(self.baseView).offset(-viewPix(24));
    }];
    [self.currentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.bottomView).offset(viewPix(13));
        make.left.equalTo(self.bottomView).offset(viewPix(10));
    }];
    [self.totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.currentLabel.mas_right);
        make.centerY.equalTo(self.currentLabel);
    }];
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.currentLabel.mas_bottom).offset(viewPix(10));
        make.left.equalTo(self.currentLabel);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bottomView).offset(viewPix(65));
        make.right.equalTo(self.bottomView).offset(-viewPix(65));
        make.centerY.equalTo(self.tipLabel);
        make.height.equalTo(@(viewPix(8)));
    }];
    [self.percentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lineView.mas_right).offset(viewPix(8));
        make.centerY.equalTo(self.lineView);
    }];
}
-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"戒酒进度" colorString:@"#282828" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _titleLabel.frame = CGRectMake(viewPix(18), viewPix(16), Screen_W-viewPix(36), viewPix(22));
    }
    return _titleLabel;
}

-(UIImageView *)baseView{
    if(!_baseView){
        _baseView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"戒烟-背景"]];
        _baseView.frame = CGRectMake(viewPix(4), viewPix(36), Screen_W-viewPix(8), viewPix(178));
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"戒烟-当前计划"]];
        _iconView.frame = CGRectMake(viewPix(24), viewPix(20), viewPix(62), viewPix(20));
    }
    return _iconView;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:2];
    }
    return _contentLabel;
}

-(UIView *)bottomView{
    if(!_bottomView){
        _bottomView = [[UIView alloc] initWithFrame:CGRectMake(viewPix(24), viewPix(84), Screen_W-viewPix(56), viewPix(70))];
        _bottomView.backgroundColor = [UIColor colorWithString:@"#F4EEFA"];
        _bottomView.cornerRidus = 10;
    }
    return _bottomView;
}

-(UILabel *)currentLabel{
    if(!_currentLabel){
        _currentLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _currentLabel;
}

-(UILabel *)totalLabel{
    if(!_totalLabel){
        _totalLabel = [UILabel lableWithText:@"" colorString:@"#606266" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _totalLabel;
}

-(UILabel *)tipLabel{
    if(!_tipLabel){
        _tipLabel = [UILabel lableWithText:@"成功率" colorString:@"#282828" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _tipLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E6E6E7"];
        _lineView.cornerRidus = viewPix(4);
    }
    return _lineView;
}

-(UIView *)progressView{
    if(!_progressView){
        _progressView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, viewPix(8))];
        _progressView.backgroundColor = [UIColor colorWithString:@"#C1A2F6"];
        _progressView.cornerRidus = viewPix(4);
    }
    return _progressView;
}

-(UILabel *)percentLabel{
    if(!_percentLabel){
        _percentLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _percentLabel;
}

@end
